#ifndef __ESP8266_H__
#define __ESP8266_H__
#include "stm32f10x.h"                  // Device header
#include <cstring>
#include "Delay.h"
using namespace std;
//*** <<< Use Configuration Wizard in Context Menu >>> ***
//<q>Enable DMA
#define USE_DMA 1
//<o>ESP8266 IO Buffer Size(in Byte)
class ESP8266
{
	private:
		USART Port;
	#if USE_DMA
		DMA RxChannel;
	#endif
	protected:

	public:
		uint8_t Buffer[512];//底层缓冲区
		uint16_t ReciveLength;//收到的数据长度
		bool ReciveFlag;//接收完成标志位
		static const char* NET_Status_String[];

		typedef enum
		{
				Error = 1,
		    GetIP,
		    Connection,
		    LostConnect,
				NoWIFI
		} NET_Status_t;

		typedef enum
		{
		    Station = 0,
		    AP,
		    AP_Station
		} Mode_t;
		
		typedef enum
		{
			AI_Link = 0,
			ESP_Touch,
			Air_Kiss
		}ConfigMethod_t;
		#if USE_DMA
		ESP8266(USART _Port,DMA _RxChannel):Port(_Port),RxChannel(_RxChannel) {};
		ESP8266(USART_TypeDef* _Port,DMA_Channel_TypeDef* _RxChannel):Port(_Port),RxChannel(_RxChannel) {};
		#else
		ESP8266(USART _Port):Port(_Port) {};
		ESP8266(USART_TypeDef* _Port):Port(_Port) {};
		#endif
		void ClearBuffer(void);
		bool CheckReturn(const char* Res,uint16_t Timeout);



		void Init(void);
		bool Reboot(void);
		bool CheckModel(void);

		bool SendCmd(const char* CMD,const char* Res,uint16_t Timeout,uint16_t Retry);
		bool SendDataPrepare(uint32_t DataLen);


		NET_Status_t GetNetworkStatus(void);
		bool SetFeedBack(bool OF);
		bool ConnectWIFI(const char* SSID,const char* Password);
		bool DisConnectWIFI(void);
		bool SetMode(Mode_t Mode);
		bool SetWIFIAutoConnect(bool OF);
		bool SetSmartConfig(ConfigMethod_t Method);
		bool StopSmartConfig(void);
		bool SetDirectTransmit(bool OF);
		bool BuildConnection(const char* Type,const char* Address,uint32_t _Port);
		bool GetReciveData(uint8_t** dp);

};


//*** <<< end of configuration section >>>    ***







#endif
